from common.base_model import BaseModel, BasicModelMixin
from exts import db
from common import constant
from common.mixins import DictMixin
from flask import g
from copy import deepcopy
from common.base_model import BaseModel, BasicModelMixin, CompanyMixin, CreateMixin, UpdateMixin, DeleteMixin


class Company(BasicModelMixin, db.Model, CreateMixin, UpdateMixin):
    __tablename__ = 'company'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(constant.MIDDLE_DB_STR_LEN), nullable=False)
    address = db.Column(db.String(constant.MIDDLE_DB_STR_LEN))
    phone = db.Column(db.NUMERIC)
    tags = db.Column(db.JSON)
    desc = db.Column(db.String(constant.MIDDLE_DB_STR_LEN))

    # 积分
    current_coins = db.Column(db.DECIMAL(20, constant.COMMON_DECIMAL), default=0, server_default='0')

    # 货号
    auto_sku_sn_is_active = db.Column(db.Boolean, default=True)
    auto_sku_sn_prefix = db.Column(db.String(constant.MIDDLE_DB_STR_LEN), default='')
    auto_sku_sn_start_index = db.Column(db.Integer, default=0)
    auto_sku_sn_len = db.Column(db.Integer, default=6)

    @classmethod
    def create(cls, commit=False, **kwargs):
        new_obj = DictMixin.from_dict(cls, kwargs)
        db.session.add(new_obj)
        if commit is True:
            db.session.commit()
        return new_obj


# class CompanySetting(BasicModelMixin, db.Model):
#     company_id = db.Column(db.Integer, db.ForeignKey('company.id'), primary_key=True)
